<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CF CMS Administrator</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="../resources/js/ext/ext-{$ext_version}/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../resources/js/ext/ext-{$ext_version}/adapter/ext/ext-base.js" ></script>
<script type="text/javascript" src="../resources/js/ext/ext-{$ext_version}/ext-all.js"></script>
<script type="text/javascript">
	Ext.BLANK_IMAGE_URL = '../resources/js/ext/ext-{$ext_version}/resources/images/default/s.gif';
	Ext.ns("Ext.App");
	Ext.Direct.addProvider({
		url: "index.php"
		,namespace: "API"
		,type: "remoting"
		,enableBuffer: false
		,actions:{
			"auth":[{"name":"login","len":1}]
			,"language":[{"name":"load", "len":0}]
		}
	});
	Ext.onReady(function(){
		Ext.QuickTips.init();
		var form = new Ext.FormPanel({
			renderTo: 'form'
			//,url: 'auth/login'
			,frame: true
			,monitorValid: true
			,labelAlign: 'right'
			,labelWidth: 70
			,defaults: {allowBlank: false, anchor: '100%', labelSeparator: ''}
			,items: [
				{
					xtype: 'textfield'
					,vtype: 'email'
					,fieldLabel: 'E-mail'
					,name: 'email'
				},{
					xtype: 'textfield'
					,inputType: 'password'
					,fieldLabel: 'Password'
					,name: 'password'
				},{
					xtype: 'combo'
					,fieldLabel: 'Language'
					,hiddenName: 'lang_id'
					,store: new Ext.data.DirectStore({
						autoLoad: true
						,proxy: new Ext.data.DirectProxy({
							directFn: API.language.load
						})
						,reader: new Ext.data.JsonReader({
							fields: ['id', 'name', 'default']	
						})
					})
					,mode: 'local'
					,valueField: 'id'
					,displayField: 'name'
					,triggerAction: 'all'
					,forceSelection: true
					,listeners: {
						render: function(combo){
							combo.getStore().on('load', function(store, records){
								var index = store.find('default', 1);
								var rec;
								if(index) rec = store.getAt(index);
								else rec = records[0];
								combo.setValue(rec.data.id);	
							});	
						}	
					}
				}
			]
			,buttons: [
				{
					text: 'Login'
					,formBind: true
					,handler: function(){
						Ext.Msg.wait('Processing...');
						
						var values = form.getForm().getValues();
						API.auth.login(values, function(r){
							if(r.success){
								window.location.href = 'index';
								return;
							}
							
							Ext.Msg.alert('Login failure', r.msg);
						});
					}
				},{
					text: 'Reset'
					,handler: function(){form.getForm().reset()}
				}
			]
		});
	});
</script>
</head>
<body>
<div style="margin:30px auto;">
<div id="form" style="margin:auto; width:300px;"></div>
</div>
</body>
</html>